﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class setpassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Checkkey();
        }
    }
    protected void Checkkey()
    {
        if (Session["codenum"] != null && Session["edituser"]!=null)
        {
            if (DBUtility.DbHelper.Decrypt(Request.QueryString["code"]) == Session["codenum"].ToString() && Session["edituser"].ToString()==Request.QueryString["name"])
            {
                if (DateTime.Now.CompareTo(Convert.ToDateTime(DBUtility.DbHelper.Decrypt(Request.QueryString["key"])).AddMinutes(15)) == 1)
                {
                    Response.Redirect("reg.aspx");
                }
                else
                {
                    setpass.Attributes.Remove("class");
                }
            }
            else
            {
                Response.Write("链接失效！");
            }
        }
        else
        {
            Response.Write("链接失效！");
        }
    }
    protected void btnOk_Click(object sender, EventArgs e)
    {
        MODEL.UserLogon model = new MODEL.UserLogon();
        BLL.UserLogon bll = new BLL.UserLogon();
        string userName = Session["edituser"].ToString();
        model.UID = bll.UserLogonListByName(userName).Tables[0].Rows[0]["Uid"].ToString();
        model.UpassWord = EncrypterMD5.MD5.Md5(txtPasswordtwo.Text.Trim(),32);

        bool flag = bll.UserLogonUpdatePassword(model);
        if (flag)
        {
            Session["codenum"] = null;
            Session["edituser"] = null;
            Response.Redirect("reg.aspx");
        }
    }
}
